package com.tool.mylibrary.ui.popupWindow;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.tool.mylibrary.R;

import java.util.List;

/**
 * Created by Google on 2018/5/4.
 */

public class PopupShowAdapter extends BaseAdapter {

    private Context context;
    private List<?> list;

    public PopupShowAdapter(Context context, List<?> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_popup_show,parent,false);
            holder=new ViewHolder();
            convertView.setTag(holder);
            holder.textView=convertView.findViewById(R.id.pop_show_text);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

//        holder.textView.setText(list.get(position));
        if (onSetView!=null){
            onSetView.setView(holder.textView,position);
        }

        return convertView;
    }

    class ViewHolder{
        TextView textView;
    }

    public  interface  OnSetView{
        void setView(TextView view,int position);
    }
    OnSetView onSetView;
    public void setOnSetView(OnSetView onSetView){
        this.onSetView=onSetView;
    }
}
